const superagent = require("superagent");
const cheerio = require("cheerio");
const baseUrl = "http://music.163.com";

function playListInfo(success, fail, id) {
    let getData = {
        id: id
    };
    superagent
        .get(baseUrl + "/playlist")
        .query(getData)
        .then(res => {
            let $ = cheerio.load(res.text);
            let tagListDom = $(".tags.f-cb .u-tag");
            let tagArray = [];
            for (let i = 0; i < tagListDom.length; i++) {
                tagArray.push(tagListDom.eq(i).find("i").text());
            }
            success({
                playListImg: $(".j-img").attr("src"),
                playListTitle: $(".cnt .f-ff2.f-brk").text(),
                tagArray: tagArray
            });
        })
        .catch(error => {
            fail(error);
        });
}
module.exports = playListInfo;